<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="module-email.utils.html" />
<link rel="prev" href="module-email.encoders.html" />
<link rel="parent" href="module-email.html" />
<link rel="next" href="module-email.utils.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>7.1.8 Exception and Defect classes</title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="7.1.7 Encoders"
  href="module-email.encoders.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="7.1 email  "
  href="module-email.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="7.1.9 miscellaneous utilities"
  href="module-email.utils.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-email.encoders.html">7.1.7 Encoders</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-email.html">7.1 email  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-email.utils.html">7.1.9 Miscellaneous utilities</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h2><a name="SECTION009180000000000000000">
7.1.8 Exception and Defect classes</a>
</h2>
<a name="module-email.errors"></a>

<p>
The following exception classes are defined in the
<tt class="module">email.errors</tt> module:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-1308' xml:id='l2h-1308' class="exception">MessageError</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
This is the base class for all exceptions that the <tt class="module">email</tt>
package can raise.  It is derived from the standard
<tt class="exception">Exception</tt> class and defines no additional methods.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-1309' xml:id='l2h-1309' class="exception">MessageParseError</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
This is the base class for exceptions thrown by the <tt class="class">Parser</tt>
class.  It is derived from <tt class="exception">MessageError</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-1310' xml:id='l2h-1310' class="exception">HeaderParseError</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Raised under some error conditions when parsing the <a class="rfc" id='rfcref-99364' xml:id='rfcref-99364'
href="http://www.faqs.org/rfcs/rfc2822.html">RFC 2822</a> headers of
a message, this class is derived from <tt class="exception">MessageParseError</tt>.
It can be raised from the <tt class="method">Parser.parse()</tt> or
<tt class="method">Parser.parsestr()</tt> methods.

<p>
Situations where it can be raised include finding an envelope
header after the first <a class="rfc" id='rfcref-99366' xml:id='rfcref-99366'
href="http://www.faqs.org/rfcs/rfc2822.html">RFC 2822</a> header of the message, finding a
continuation line before the first <a class="rfc" id='rfcref-99368' xml:id='rfcref-99368'
href="http://www.faqs.org/rfcs/rfc2822.html">RFC 2822</a> header is found, or finding
a line in the headers which is neither a header or a continuation
line.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-1311' xml:id='l2h-1311' class="exception">BoundaryError</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Raised under some error conditions when parsing the <a class="rfc" id='rfcref-99370' xml:id='rfcref-99370'
href="http://www.faqs.org/rfcs/rfc2822.html">RFC 2822</a> headers of
a message, this class is derived from <tt class="exception">MessageParseError</tt>.
It can be raised from the <tt class="method">Parser.parse()</tt> or
<tt class="method">Parser.parsestr()</tt> methods.

<p>
Situations where it can be raised include not being able to find the
starting or terminating boundary in a <span class="mimetype">multipart/*</span> message
when strict parsing is used.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-1312' xml:id='l2h-1312' class="exception">MultipartConversionError</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Raised when a payload is added to a <tt class="class">Message</tt> object using
<tt class="method">add_payload()</tt>, but the payload is already a scalar and the
message's <span class="mailheader">Content-Type:</span> main type is not either
<span class="mimetype">multipart</span> or missing.  <tt class="exception">MultipartConversionError</tt>
multiply inherits from <tt class="exception">MessageError</tt> and the built-in
<tt class="exception">TypeError</tt>.

<p>
Since <tt class="method">Message.add_payload()</tt> is deprecated, this exception is
rarely raised in practice.  However the exception may also be raised
if the <tt class="method">attach()</tt> method is called on an instance of a class
derived from <tt class="class">MIMENonMultipart</tt> (e.g. <tt class="class">MIMEImage</tt>).
</dl>

<p>
Here's the list of the defects that the <tt class="class">FeedParser</tt> can find while
parsing messages.  Note that the defects are added to the message where the
problem was found, so for example, if a message nested inside a
<span class="mimetype">multipart/alternative</span> had a malformed header, that nested message
object would have a defect, but the containing messages would not.

<p>
All defect classes are subclassed from <tt class="class">email.errors.MessageDefect</tt>, but
this class is <em>not</em> an exception!

<p>

<span class="versionnote">New in version 2.4:
All the defect classes were added.</span>

<p>

<ul>
<li><tt class="class">NoBoundaryInMultipartDefect</tt> - A message claimed to be a
      multipart, but had no <span class="mimetype">boundary</span> parameter.

<p>
</li>
<li><tt class="class">StartBoundaryNotFoundDefect</tt> - The start boundary claimed in the
      <span class="mailheader">Content-Type:</span> header was never found.

<p>
</li>
<li><tt class="class">FirstHeaderLineIsContinuationDefect</tt> - The message had a
      continuation line as its first header line.

<p>
</li>
<li><tt class="class">MisplacedEnvelopeHeaderDefect</tt> - A ``Unix From'' header was found
      in the middle of a header block.

<p>
</li>
<li><tt class="class">MalformedHeaderDefect</tt> - A header was found that was missing a
      colon, or was otherwise malformed.

<p>
</li>
<li><tt class="class">MultipartInvariantViolationDefect</tt> - A message claimed to be a
      <span class="mimetype">multipart</span>, but no subparts were found.  Note that when a
      message has this defect, its <tt class="method">is_multipart()</tt> method may return
      false even though its content type claims to be <span class="mimetype">multipart</span>.
</li>
</ul>

<p>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="7.1.7 Encoders"
  href="module-email.encoders.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="7.1 email  "
  href="module-email.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="7.1.9 miscellaneous utilities"
  href="module-email.utils.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-email.encoders.html">7.1.7 Encoders</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-email.html">7.1 email  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-email.utils.html">7.1.9 Miscellaneous utilities</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
